<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Style short summary.
 *
 * Style description.
 *
 * @version 1.0
 * @author GALAXY
 */
class Goods_style_model extends CI_Model
{
    public $goods_style_id;
    public $title;
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    //插入新材质
    public function insert_goods_style($goods_styleModel)
    {
        return $this->db->insert('goods_style',$goods_styleModel);
    }

    //由材质id 获取材质
    public function get_goods_style_by_id($goods_style_id)
    {
        return $this->db->select()->from('goods_style')->where(array('goods_style_id'=>$goods_style_id))->get()->row();
    }

    //获取所有材质
    public function get_allgoods_style()
    {
        return $this->db->select()->from('goods_style')->get()->result();
    }

    public function get_title($goods_style_id)
    {
        return $this->db->select('title')->from('goods_style')->where(array('goods_style_id'=>$goods_style_id))->get()->row();
    }


    //更新材质
    public function edit_goods_style($goods_styleModel)
    {

        return  $this->db->update('goods_style',$goods_styleModel,array('goods_style_id'=>$goods_styleModel->goods_style_id));

    }

    //删除材质
    public function del_goods_style_byid($goods_style_id)
    {
        return $this->db->delete('goods_style',array('goods_style_id'=>$goods_style_id));
    }

    //批量删除材质
    public function batchdel_goods_style($goods_style_ids)
    {
        $this->db->trans_begin();
        foreach($goods_style_ids as $goods_styleiditem)
        {
            $this->db->delete('goods_style',array('goods_style_id'=>$goods_styleiditem));
        }
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
            return 0;
        }
        else
        {
            $this->db->trans_commit();
            return 1;
        }
    }



    /**
     * @param mixed $cpage
     * @param mixed $pagesize
     * @param mixed $files
     * @param mixed $tabel
     * @param mixed $order
     */
    public function get_page($cpage,$pagesize,$files,$tabel,$order,$temp_id,$where)
    {
        $sql="SELECT $files FROM $tabel a JOIN (select $temp_id from $tabel $where limit ".($cpage-1)*$pagesize.", $pagesize) b ON a.$temp_id = b.$temp_id ";
        $sql_count="select count('$temp_id') as _count from $tabel $where";
        $data['objlist']=$this->db->query($sql)->result();
        $data['count']=$this->db->query($sql_count)->result();
        return $data;
    }

}